/**
 * 医嘱项管理初始化
 */
var CdcOrdmast = {
    id: "CdcOrdmastTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcOrdmast.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '索引码', field: 'xcode', align: 'center', valign: 'middle', sortable: true},
        {title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true},
        {title: '药品通用名', field: 'drugCommonName', align: 'center', valign: 'middle', sortable: true},
        {title: '化学通用名', field: 'chemCommonName', align: 'center', valign: 'middle', sortable: true},
        {title: '大类', field: 'busOrderCate.description', align: 'center', valign: 'middle', sortable: true},
        {title: '子类', field: 'busOrderSubcate.description', align: 'center', valign: 'middle', sortable: true},
        {title: '类型', field: 'busOrderType.description', align: 'center', valign: 'middle', sortable: true},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true,formatter:function(value,row,index) {
            return value?"是":"否";
        }}
    ];
};

/**
 * 检查是否选中
 */
CdcOrdmast.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcOrdmast.seItem = selected[0];
        return true;
    }
};

/**
 * 点击新增医嘱项
 */
CdcOrdmast.add = function () {
    var index = Sys.open('新增医嘱项',Sys.backendPath + '/cdc/cdcordmast/to_add',['800px', '330px']);
    this.layerIndex = index;
};

/**
 * 打开查看医嘱项详情
 */
CdcOrdmast.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('医嘱项详情',Sys.backendPath + '/cdc/cdcordmast/to_update/' + id,['800px', '330px']);
        this.layerIndex = index;
    }
};

/**
 * 删除医嘱项
 */
CdcOrdmast.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/cdcordmast/delete", function (data) {
	            Sys.success("删除成功!");
	            CdcOrdmast.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("cdcOrdmastId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除医嘱项?",operation);
    }
};

/**
 * 查询医嘱项列表
 */
CdcOrdmast.search = function () {
    var queryData = {};
    queryData['code'] = $("#code").val();
    queryData['description'] = $("#description").val();
    queryData['drugCommonName'] = $("#drugCommonName").val();
    queryData['chemCommonName'] = $("#chemCommonName").val();
    queryData['busOrderCateId'] = $("#busOrderCateId").val();
    queryData['busOrderSubcateId'] = $("#busOrderSubcateId").val();
    queryData['busOrderTypeId'] = $("#busOrderTypeId").val();
    queryData['dataId'] = $("#dataId").val();
    queryData['isActive'] = $("#isActive").val();
    CdcOrdmast.table.refresh({query: queryData});
};

$(function () {
    CdcOrdmast.sysDataId=window.parent.baseData.sysDataId;

    var defaultColunms = CdcOrdmast.initColumn();
    var table = new BSTable(CdcOrdmast.id, Sys.backendPath + "/cdc/cdcordmast/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(10);
    table.setQueryParams({ "dataId": CdcOrdmast.sysDataId });
    CdcOrdmast.table = table.init();
});
